# -*- coding: utf-8 -*-

import os
import sys
import wx
import wx.html as html

__all__ = ['create']

def create(parent=None, filename="index.htm"):
    return WbHtmlPanel(parent, filename)


class WbHtmlPanel(wx.Panel):
    def __init__(self, parent, filename):
        wx.Panel.__init__(self, parent, -1, 
              style=wx.EXPAND|wx.NO_FULL_REPAINT_ON_RESIZE)
        self.filename = filename
        self.cwd = os.path.split(sys.argv[0])[0]
        if not self.cwd:
            self.cwd = os.getcwd()

        self.html = html.HtmlWindow(self)
        if "gtk2" in wx.PlatformInfo:
            self.html.SetStandardFonts()
        
        self.sizer = wx.BoxSizer()
        self.sizer.Add(self.html, 1, wx.EXPAND, 0)
        self.SetSizer(self.sizer)

        self.OnShowDefault(None)

    def OnShowDefault(self, event):
        from Main import opj
        name = os.path.join(self.cwd, opj('htm/%s' % self.filename))
        self.html.LoadPage(name)

class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1)
        
        p = create(self)
        p.Fit()

if __name__ == '__main__':
    app = wx.PySimpleApp()
    TestFrame().Show()
    app.MainLoop()
    